﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;

public partial class admin_quanlilichdien : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        load();
    }
    LichDien ld = new LichDien();
    private void load()
    {
        ASPxGridView1.DataSource = LichDien.ViewAll();
        ASPxGridView1.DataBind();
        //load du lieu cho combo chuong trinh
        ListEditItem ct;
        int n = 0;
        foreach (var u in ChuongTrinh.ChuongTrinhList())
        {
            ct=new ListEditItem(u.tenct,u.mact);
            ASPxComboBox1.Items.Insert(n,ct);
            n++;
        }
        
    }
    
    protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
        ld.deleteLichdien(int.Parse(e.Values["mald"].ToString()));

        e.Cancel = true;
        ASPxGridView1.CancelEdit();
        load();
        
    }
    
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        TimeSpan giobatdau = TimeSpan.Parse(ASPxTextBox1.Text);
        TimeSpan gioketthuc = TimeSpan.Parse(ASPxTextBox2.Text);
        DateTime ngaydien = ASPxDateEdit1.Date;
        int mact = int.Parse(ASPxComboBox1.SelectedItem.Value.ToString());
        ld.insertLichdien(ngaydien, giobatdau,gioketthuc,mact);        
        load();
        ASPxComboBox1.SelectedIndex = -1;
        ASPxTextBox1.Text = "";
        ASPxTextBox2.Text = "";
        ASPxDateEdit1.Text = "";
    }

    
}